package org.example.com.kotlinlab.delegate.property_delegate.custom_delegate

import kotlin.reflect.KProperty

class Resource

class Owner {
    var varResource: Resource by ResourceDelegate()
}

class ResourceDelegate(private var resource: Resource = Resource()) {
    operator fun getValue(thisRef: Owner, property: KProperty<*>): Resource {
        return resource
    }

    operator fun setValue(thisReg: Owner, property: KProperty<*>, value: Any?) {
        if (value is Resource) {
            resource = value
        }
    }
}

fun main() {
    val owner = Owner()

    val res = Resource()
    ResourceDelegate(res)
}
